local dingfa = fk.CreateSkill {
  name = "lvshi__dingfa",
  tags = {"ready_skill"},
}

Fk:loadTranslationTable {
  ["lvshi__dingfa"] = "鼎阀",
  [":lvshi__dingfa"] = "<a href='diy_ready_skill'>蓄势技</a>，出牌阶段，你可令任意名手牌数不大于你的角色摸一张牌，然后这些角色须使用一张牌或交给你一张牌。",
  ["#lvshi__dingfa-prompt"] = "鼎阀：令任意名手牌数不大于你的角色摸一张牌，然后其须用牌或给牌",
  ["#lvshi__dingfa-use"] = "鼎阀：你须使用一张牌，否则须交给 %src 一张牌",
  ["#lvshi__dingfa-give"] = "鼎阀：请交给 %src 一张牌",

  ["$lvshi__dingfa1"] = "居北望南，天下碌碌之辈，诚不足虑也。",
  ["$lvshi__dingfa2"] = "驱韩缚马，擒尔雄兵十万，不过覆手之间。",
}
local DIY = require "packages/diy_utility/diy_utility"

dingfa:addEffect("active", {
  anim_type = "big",
  min_target_num = 1,
  card_num = 0,
  prompt = "#lvshi__dingfa-prompt",
  can_use = function(self, player)
    return not DIY.isReadying(player, dingfa.name)
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected)
    return to_select:getHandcardNum() <= player:getHandcardNum()
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local tos = effect.tos
    for _, to in ipairs(tos) do
      if not to.dead then
        to:drawCards(1, self.name)
      end
    end
    for _, to in ipairs(tos) do
      if player.dead then break end
      if not to.dead then
        local use = room:askToPlayCard(to, {
          pattern = ".",
          skill_name = dingfa.name,
          prompt = "#lvshi__dingfa-use:".. player.id,
          extra_data = { extraUse = true, bypass_times = true },
        })
        if not use and not to:isNude() and not player.dead then
          local cards = room:askToCards(to, {
            min_num = 1,
            max_num = 1,
            include_equip = true,
            skill_name = dingfa.name,
            cancelable = false,
            prompt = "#lvshi__dingfa-give:"..player.id
          })
          if #cards > 0 then
            room:obtainCard(player, cards, true, fk.ReasonGive, to, dingfa.name)
          end
        end
      end
    end
  end,
})

return dingfa